#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, q, l[300005], r[300005], opt, p, s, e, a, b, c, d;

signed main() {
	freopen("study.in", "r", stdin);
	freopen("study.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	if (n <= 1000 && q <= 1000) {
		for (int i = 1; i < n; ++i) cin >> l[i] >> r[i];
		while (q--) {
			cin >> opt;
			if (opt == 1) {
				cin >> p >> s >> e;
				l[p] = s;
				r[p] = e;
			} else {
				cin >> a >> b >> c >> d;
				if (a == c) {
					cout << "0\n";
				} else if (a < c) {
					int tme = b, ans = 0;
					for (int i = a; i < c; ++i) {
						if (tme >= r[i]) {
							ans += tme - r[i] + 1;
							tme = r[i];
						} else {
							tme = max(tme, l[i]) + 1;

						}
					}
					if (tme > d) ans += tme - d;
					cout << ans << "\n";
				} else {
					int tme = b, ans = 0;
					for (int i = a - 1; i >= c; --i) {
						if (tme >= r[i]) {
							ans += tme - r[i] + 1;
							tme = r[i];
						} else {
							tme = max(tme, l[i]) + 1;

						}
					}
					if (tme > d) ans += tme - d;
					cout << ans << "\n";
				}
			}
		}
	}
	return 0;
}
